package com.andy.nature.ui.fragment

import androidx.recyclerview.widget.LinearLayoutManager
import com.andy.common.base.BaseBottomDialogFragment
import com.andy.common.extend.setOnIMClickListener
import com.andy.nature.databinding.FragmentMessageBinding
import com.andy.nature.ui.adapter.MessageAdapter
import com.andy.nature.vm.CommonViewModel

/**
 * @author Andy
 * @date 2023/8/24
 * @description MessageFragment
 */
class MessageFragment : BaseBottomDialogFragment<FragmentMessageBinding, CommonViewModel>() {
    private val messageAdapter: MessageAdapter by lazy {
        MessageAdapter()
    }

    override fun getViewBinding(): FragmentMessageBinding {
        return FragmentMessageBinding.inflate(layoutInflater)
    }

    override fun getViewModel(): Class<CommonViewModel> {
        return CommonViewModel::class.java
    }

    companion object {
        const val PAGE_TAG = "MessageFragment"
        fun newInstance(): MessageFragment {
            return MessageFragment()
        }
    }

    override fun initObserve() {
        mViewModel.testLiveData.observe(this) {
            messageAdapter.setData(it)
        }
    }

    override fun initData() {
        mBinding?.apply {
            rvList.layoutManager = LinearLayoutManager(requireContext())
            rvList.adapter = messageAdapter
        }
    }

    override fun initAction() {
        mBinding?.apply {
            ivClose.setOnIMClickListener {
                dismissAllowingStateLoss()
            }
        }
    }
}